#!/usr/bin/env python

import FuseStat
import Node

class FileSystem:
   def __init__(self, clusterSize, dataArea):
      self.clusterSize = clusterSize
      self.dataArea = dataArea
      self.rootDirs = []
      
      self.name = "No FS"
      
   def __eq__(self, other):
      if other is None:
         return False
      return self.clusterSize == other.clusterSize and self.dataArea == other.dataArea
      
   def getName(self):
      return self.name
      
   def __str__(self): return self.getName()

#   def __str__(self):
#      return str(self.clusterSize) + ", " + str(self.dataArea)
      
   def getChildren(self):
      return [Node.Node("."), Node.Node("..")] + self.rootDirs   # These are directories
      
   def getChild(self, name):
      # Name will be in the form of C## where ## will be the cluster number
      for e in self.getChildren()[2:]:
         if e.getName() == name:
            return e
            
      return None
      
   def isDirectory(self):
      return True
      
   def getAttribs(self):
      return FuseStat.DirStat()
      
   def read(self, startCLuster, length):
      im = open(self.image.imageName)
      im.seek((startCLuster * self.clusterSize + self.dataArea) * 512)

      return im.read(length)
